package com.class04.stream;

import com.class04.reference.data.Employee;
import com.class04.reference.data.EmployeeData;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

/**
 * @ClassDescription: 测试stream流中间操作
 * @JdkVersion: 17
 * @Author: yxy
 * @Created: 2023/11/29 20:20
 */
public class StreamAPITest1 {
    //    练习：查询员工表中薪资大于7000的员工信息
    @Test
    public void test1() {
        List<Employee> list = EmployeeData.getEmployees();
        Stream<Employee> stream = list.stream();
//        stream.filter(employee -> employee.getSalary()>7000)
//                .forEach(System.out::println);
//        list.stream().filter(employee -> employee.getSalary()>7000).limit(2).forEach(System.out::println);

//        list.stream().skip(3).forEach(System.out::println);
        list.add(new Employee(1009,"经济",34,888.99));
        list.add(new Employee(1009,"经济",34,888.99));
        list.add(new Employee(1009,"经济",34,888.99));
        list.add(new Employee(1009,"经济",34,888.99));
        list.add(new Employee(1009,"经济",34,888.99));
//        list.stream().forEach(System.out::println);
        list.stream().distinct().forEach(System.out::println);


    }
    @Test//2-映射
    public void test2(){
//        转换为大写
        List<String> list = Arrays.asList("aa", "bb", "cc", "bb");
        list.stream().map(str->str.toUpperCase()).forEach(System.out::println);
        list.stream().map(String::toUpperCase).forEach(System.out::println);
        list.stream().forEach(System.out::println);

    }
    @Test
    public void test(){
//        方式一：获取
//        EmployeeData.getEmployees().stream().
//                filter(employee -> employee.getName().length()>3)
//                .forEach(System.out::println);
//        方式二：：
        EmployeeData.getEmployees().stream().map(emp->emp.getName()).
                filter(name->name.length()>3).forEach(System.out::println);
    }
}
